from django.http import HttpResponseRedirect
from django.conf import settings
import os

def favicon_redirect(request):
    """重定向favicon请求到正确的路径"""
    favicon_path = os.path.join(settings.BASE_DIR, 'visualizer', 'static', 'visualizer', 'js', 'favicon.ico')
    if os.path.exists(favicon_path):
        # 返回重定向到实际的favicon文件
        return HttpResponseRedirect('/static/visualizer/js/favicon.ico')
    else:
        # 如果文件不存在，返回404
        from django.http import HttpResponseNotFound
        return HttpResponseNotFound('Favicon not found')